import utils from '@/utils';

const user = {
  namespaced: true,
  state: () => ({
    openId: '',
    userInfo: {},
    /**
     * 客服手机号
     */
    paramPhone: '',
    /** 服务类型 */
    serviceType: [
      {
        title: '拌料单',
        iconImg: '/static/my/ywc.png',
        FormId: 'ke839458d888346839f2a1faf963b6f76',
        FieldKeys: '',
        number: 0,
      },

      {
        title: '上料单',
        iconImg: '/static/my/pay.png',
        FormId: 'k7b26c673cfe2421ea29a789b656be38a',
        FieldKeys: '',
      },
      {
        title: '产出单',
        iconImg: '/static/my/pay.png',
        FormId: 'k9d89ba7552604402a30d5d5cf3dc4001',
        FieldKeys: '',
        number: 0,
      },
      {
        title: '修模单',
        iconImg: '/static/my/pay.png',
        FormId: 'k1a7a709334ac4681a11930f9d332a5ba',
        FieldKeys: '',
        number: 0,
      },
    ],
  }),
  getters: {
    openId(state: any) {
      return state.openId;
    },
    userInfo(state: any) {
      return state.userInfo;
    },
    paramPhone(state: any) {
      return state.paramPhone;
    },
    serviceType(state: any) {
      return state.serviceType;
    },
  },
  mutations: {
    updateOpenId(state: any, v: any) {
      state.openId = v;
      setTimeout(() => {
        user.mutations.updateUserInfo(state, v);
        user.mutations.updateParamPhone(state);
      }, 100);
    },
    async updateUserInfo(state: any, v?: any) {
      // const res: any = await queryUser({
      //   openId: user.getters.openId(state),
      // });
      // if (res.success && res.data) {
      //   state.userInfo = res.data;
      //   utils.telephone = res.data;
      // }
      state.userInfo = v;
    },
    async updateParamPhone(state: any) {
      // const res: any = await getParam({ paramGroup: 'SYS_LINKMAN' });
      // if (res.success) {
      //   state.paramPhone = res.data[0]?.paramValue;
      // }
    },
  },
};
export default user;
